package com.cy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cy.pojo.User;
import com.cy.mapper.UserMapper;
import com.cy.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author cy
 * @since 2021-11-21
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper mapper;

    @Override
    public List<User> queryPage(Integer pageNumber) {
        Page<User> userPage = new Page<User>(pageNumber, 5);
        List<User> users = mapper.selectPage(userPage, new QueryWrapper<User>().eq("status", 1)).getRecords();
        return users;
    }

    @Override
    public List<User> queryPage(Integer pageNumber, Integer size) {
        Page<User> userPage = new Page<User>(pageNumber, size);
        List<User> users = mapper.selectPage(userPage, new QueryWrapper<User>().eq("status", 1)).getRecords();
        return users;
    }

    @Override
    public List<User> queryPage(Integer pageNumber, String name) {
        Page<User> userPage = new Page<User>(pageNumber,5);
        List<User> users = mapper.selectPage(userPage, new QueryWrapper<User>()
                .eq("status", 1)
                .like("name",name)
        ).getRecords();
        System.out.println(users);
        return users;
    }
}
